package com.horse.cloud.member.user.feignclients;

import com.horse.cloud.framework.general.enums.ResponseCodeEnums;
import com.horse.cloud.framework.general.response.Response;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @create : Created by intelliJ IDEA 17.2
 * @author : bing.Pan
 * @e-mail : 15923508369@163.com
 * @gmdate : 10 26 2017 17:19
 * @sidesc : feign 客户端集成hystrix 熔断退回实现
 *         这里通过FallbackFactory 实现检查退回原因
 *         MemberAccountClient 的fallback类实现FallbackFactory接口并覆写create 方法
 *         覆写MemberAccountClient接口下的方法，定义接口退回数据和日志内容
 */

@Component
public class MemberAccountFallBackFactory implements FallbackFactory<MemberAccountClient>{
    private static final Logger LOGGER = LoggerFactory.getLogger(MemberAccountFallBackFactory.class);

    @Override
    public MemberAccountClient create(Throwable throwable) {
        return new MemberAccountClient() {
            @Override
            public Response getMemberAccount() {
                MemberAccountFallBackFactory.LOGGER.error("【cloud-member-user】 调用 [/memberAccount/getMemberAccount] 时发生异常异常信息 [{}]", throwable);
                return new Response<>(ResponseCodeEnums.MINOR_SERVER_HYSTRIX_FALLBACK,"/memberAccount/getMemberAccount");
            }
        };
    }
}
